#include "stdafx.h"
#include "ModelShader.h"

int ModelShader::Init(char *fileVertexShader, char *fileFragmentShader)
{
	vertexShader = esLoadShader(GL_VERTEX_SHADER, fileVertexShader);
	if ( vertexShader == 0)
		return -1;

	fragmentShader = esLoadShader(GL_FRAGMENT_SHADER, fileFragmentShader);
	if ( fragmentShader == 0)
		return -2;

	program = esLoadProgram(vertexShader, fragmentShader);
	
	//Finding location of attribute/uniform variable
	VertPosition = glGetAttribLocation(program, "a_VertPosition");
	VertTexCoord = glGetAttribLocation(program, "a_VertTexCoord");
	VertNorm = glGetAttribLocation(program, "a_VertNorm");
	VertBiNorm = glGetAttribLocation(program, "a_VertBiNorm");
	VertTangent = glGetAttribLocation(program, "a_VertTangent");
	WVPMatrix = glGetUniformLocation(program, "u_WVPMatrix");
	WMatrix = glGetUniformLocation(program, "u_WMatrix");
	CameraPosition = glGetUniformLocation(program, "u_CameraPosition");
	LightPosition = glGetUniformLocation(program, "u_LightPosition");
	ObjTexture = glGetUniformLocation(program, "u_ObjTexture");
	NormMapTexture = glGetUniformLocation(program, "u_NormMapTexture");
	Step = glGetUniformLocation(program, "u_Step");

	return 0;
}

ModelShader::~ModelShader()
{
	glDeleteProgram(program);
	glDeleteShader(vertexShader);
	glDeleteShader(fragmentShader);
}